home *** CD-ROM | disk | FTP | other *** search
Wrap
RRRRWWWWTTTTPPPPttttrrrrOOOOrrrrddddeeeerrrreeeeddddVVVVeeeeccccttttoooorrrr((((3333CCCC++++++++)))) RRRRWWWWTTTTPPPPttttrrrrOOOOrrrrddddeeeerrrreeeeddddVVVVeeeeccccttttoooorrrr((((3333CCCC++++++++)))) NNNNaaaammmmeeee RWTPtrOrderedVector<T> - Rogue Wave library class SSSSyyyynnnnooooppppssssiiiissss #include <rw/tpordvec.h> RWTPtrOrderedVector<T> ordvec; PPPPlllleeeeaaaasssseeee NNNNooootttteeee!!!! IIIIffff yyyyoooouuuu ddddoooo nnnnooootttt hhhhaaaavvvveeee tttthhhheeee SSSSttttaaaannnnddddaaaarrrrdddd CCCC++++++++ LLLLiiiibbbbrrrraaaarrrryyyy,,,, uuuusssseeee tttthhhheeee iiiinnnntttteeeerrrrffffaaaacccceeee ddddeeeessssccccrrrriiiibbbbeeeedddd hhhheeeerrrreeee.... OOOOtttthhhheeeerrrrwwwwiiiisssseeee,,,, uuuusssseeee tttthhhheeee iiiinnnntttteeeerrrrffffaaaacccceeee ttttoooo RRRRWWWWTTTTPPPPttttrrrrOOOOrrrrddddeeeerrrreeeeddddVVVVeeeeccccttttoooorrrr described in the Class Reference. DDDDeeeessssccccrrrriiiippppttttiiiioooonnnn RRRRWWWWTTTTPPPPttttrrrrOOOOrrrrddddeeeerrrreeeeddddVVVVeeeeccccttttoooorrrr<<<<TTTT>>>> is a pointer-based oooorrrrddddeeeerrrreeeedddd collection. That is, the items in the collection have a meaningful ordered relationship with respect to one another and can be accessed by an index number. The order is set by the order of insertion. Duplicates are allowed. The class is implemented as a vector, allowing efficient insertion and retrieval from the end of the collection, but somewhat slower from the beginning of the collection. The class TTTT must have: well-defined equality semantics (TTTT::::::::ooooppppeeeerrrraaaattttoooorrrr========((((ccccoooonnnnsssstttt TTTT&&&&))))). PPPPeeeerrrrssssiiiisssstttteeeennnncccceeee Isomorphic EEEExxxxaaaammmmpppplllleeee #include <rw/tpordvec.h> #include <rw/rstream.h> main() { RWTPtrOrderedVector<double> vec; vec.insert(new double(22.0)); vec.insert(new double(5.3)); vec.insert(new double(-102.5)); vec.insert(new double(15.0)); vec.insert(new double(5.3)); cout << vec.entries() << " entries0 << endl; // Prints "5" for (int i=0; i<vec.length(); i++) cout << *vec[i] << endl; vec.clearAndDestroy(); PPPPaaaaggggeeee 1111 RRRRWWWWTTTTPPPPttttrrrrOOOOrrrrddddeeeerrrreeeeddddVVVVeeeeccccttttoooorrrr((((3333CCCC++++++++)))) RRRRWWWWTTTTPPPPttttrrrrOOOOrrrrddddeeeerrrreeeeddddVVVVeeeeccccttttoooorrrr((((3333CCCC++++++++)))) return 0; } Program output: 5 entries 22 5.3 -102.5 15 5.3 .Ex PPPPuuuubbbblllliiiicccc CCCCoooonnnnssssttttrrrruuuuccccttttoooorrrrssss RRRRWWWWTTTTPPPPttttrrrrOOOOrrrrddddeeeerrrreeeeddddVVVVeeeeccccttttoooorrrr<T>(size_t capac=RWDEFAULT_CAPACITY); Creates an empty ordered vector with capacity ccccaaaappppaaaacccc. Should the number of items exceed this value, the vector will be resized automatically. RRRRWWWWTTTTPPPPttttrrrrOOOOrrrrddddeeeerrrreeeeddddVVVVeeeeccccttttoooorrrr<T>(const RWTPtrOrderedVector<T>& c); Constructs a new ordered vector as a shallow copy of cccc. After construction, pointers will be shared between the two collections. PPPPuuuubbbblllliiiicccc OOOOppppeeeerrrraaaattttoooorrrrssss RWTPtrOrderedVector<T>& ooooppppeeeerrrraaaattttoooorrrr====(const RWTPtrOrderedVector& c); Sets self to a shallow copy of cccc. Afterwards, pointers will be shared between the two collections. T*& ooooppppeeeerrrraaaattttoooorrrr(((())))(size_t i); T* const& ooooppppeeeerrrraaaattttoooorrrr(((())))(size_t i) const; Returns a pointer to the iiiith value in the vector. The first variant can be used as an llllvvvvaaaalllluuuueeee, the second cannot. The index iiii must be between zero and the number of items in the collection less one. No bounds checking is performed. T*& ooooppppeeeerrrraaaattttoooorrrr[[[[]]]](size_t i); T* const& PPPPaaaaggggeeee 2222 RRRRWWWWTTTTPPPPttttrrrrOOOOrrrrddddeeeerrrreeeeddddVVVVeeeeccccttttoooorrrr((((3333CCCC++++++++)))) RRRRWWWWTTTTPPPPttttrrrrOOOOrrrrddddeeeerrrreeeeddddVVVVeeeeccccttttoooorrrr((((3333CCCC++++++++)))) ooooppppeeeerrrraaaattttoooorrrr[[[[]]]](size_t i) const; Returns a pointer to the iiiith value in the vector. The first variant can be used as an llllvvvvaaaalllluuuueeee, the second cannot. The index iiii must be between zero and the number of items in the collection less one, or an exception of type RRRRWWWWBBBBoooouuuunnnnddddssssEEEErrrrrrrroooorrrr will be thrown. PPPPuuuubbbblllliiiicccc MMMMeeeemmmmbbbbeeeerrrr FFFFuuuunnnnccccttttiiiioooonnnnssss void aaaappppppppeeeennnndddd(T* a); Appends the item pointed to by aaaa to the end of the vector. The collection will automatically be resized if this causes the number of items in the collection to exceed the capacity. T*& aaaatttt(size_t i); T* const& aaaatttt(size_t i) const; Returns a pointer to the iiiith value in the vector. The first variant can be used as an llllvvvvaaaalllluuuueeee, the second cannot. The index iiii must be between zero and the number of items in the collection less one, or an exception of type RRRRWWWWBBBBoooouuuunnnnddddssssEEEErrrrrrrroooorrrr will be thrown. void cccclllleeeeaaaarrrr(); Removes all items from the collection. void cccclllleeeeaaaarrrrAAAAnnnnddddDDDDeeeessssttttrrrrooooyyyy(); Removes all items from the collection aaaannnndddd deletes them. RWBoolean ccccoooonnnnttttaaaaiiiinnnnssss(const T* a) const; Returns TTTTRRRRUUUUEEEE if the collection contains an item that is equal to the object pointed to by aaaa, FFFFAAAALLLLSSSSEEEE otherwise. A linear search is done. Equality is measured by the class-defined equality operator for type TTTT. T* const * ddddaaaattttaaaa() const; PPPPaaaaggggeeee 3333 RRRRWWWWTTTTPPPPttttrrrrOOOOrrrrddddeeeerrrreeeeddddVVVVeeeeccccttttoooorrrr((((3333CCCC++++++++)))) RRRRWWWWTTTTPPPPttttrrrrOOOOrrrrddddeeeerrrreeeeddddVVVVeeeeccccttttoooorrrr((((3333CCCC++++++++)))) Returns a pointer to the raw data of the vector. The contents should not be changed. Should be used with care. size_t eeeennnnttttrrrriiiieeeessss() const; Returns the number of items currently in the collection. T* ffffiiiinnnndddd(const T* target) const; Returns a pointer to the first object encountered which is equal to the object pointed to by ttttaaaarrrrggggeeeetttt, or nnnniiiillll if no such object can be found. Equality is measured by the class-defined equality operator for type TTTT. T*& ffffiiiirrrrsssstttt(); T* const& ffffiiiirrrrsssstttt() const; Returns a pointer to the first item in the vector. An exception of type RRRRWWWWBBBBoooouuuunnnnddddssssEEEErrrrrrrroooorrrr will occur if the vector is empty. size_t iiiinnnnddddeeeexxxx(const T* a) const; Performs a linear search, returning the index of the first object that is equal to the object pointed to by aaaa, or RRRRWWWW____NNNNPPPPOOOOSSSS if there is no such object. Equality is measured by the class-defined equality operator for type TTTT. void iiiinnnnsssseeeerrrrtttt(T* a); Adds the object pointed to by aaaa to the end of the vector. The collection will be resized automatically if this causes the number of items to exceed the capacity. void iiiinnnnsssseeeerrrrttttAAAAtttt(size_t i, T* a); Adds the object pointed to by aaaa at the index position iiii. The item previously at position iiii is moved to iiii++++1111, eeeettttcccc. The collection will be resized automatically if this causes the number of items to exceed the capacity. The index iiii must be between 0 and the number of items in the vector or an exception of type RRRRWWWWBBBBoooouuuunnnnddddssssEEEErrrrrrrroooorrrr will occur. PPPPaaaaggggeeee 4444 RRRRWWWWTTTTPPPPttttrrrrOOOOrrrrddddeeeerrrreeeeddddVVVVeeeeccccttttoooorrrr((((3333CCCC++++++++)))) RRRRWWWWTTTTPPPPttttrrrrOOOOrrrrddddeeeerrrreeeeddddVVVVeeeeccccttttoooorrrr((((3333CCCC++++++++)))) RWBoolean iiiissssEEEEmmmmppppttttyyyy() const; Returns TTTTRRRRUUUUEEEE if there are no items in the collection, FFFFAAAALLLLSSSSEEEE otherwise. T*& llllaaaasssstttt(); T* const& llllaaaasssstttt() const; Returns a pointer to the last item in the collection. If there are no items in the collection then an exception of type RRRRWWWWBBBBoooouuuunnnnddddssssEEEErrrrrrrroooorrrr will occur. size_t lllleeeennnnggggtttthhhh() const; Returns the number of items currently in the collection. size_t ooooccccccccuuuurrrrrrrreeeennnncccceeeessssOOOOffff(const T* a) const; Performs a linear search, returning the number of objects in the collection that are equal to the object pointed to by aaaa. Equality is measured by the class-defined equality operator for type TTTT. void pppprrrreeeeppppeeeennnndddd(T* a); Adds the item pointed to by aaaa to the beginning of the collection. The collection will be resized automatically if this causes the number of items to exceed the capacity. T* rrrreeeemmmmoooovvvveeee(const T* a); Performs a linear search, removing the first object which is equal to the object pointed to by aaaa and returns a pointer to it, or nnnniiiillll if no such object could be found. Equality is measured by the class-defined equality operator for type TTTT. size_t rrrreeeemmmmoooovvvveeeeAAAAllllllll(const T* a); Performs a linear search, removing all objects which are equal to the PPPPaaaaggggeeee 5555 RRRRWWWWTTTTPPPPttttrrrrOOOOrrrrddddeeeerrrreeeeddddVVVVeeeeccccttttoooorrrr((((3333CCCC++++++++)))) RRRRWWWWTTTTPPPPttttrrrrOOOOrrrrddddeeeerrrreeeeddddVVVVeeeeccccttttoooorrrr((((3333CCCC++++++++)))) object pointed to by aaaa. Returns the number of objects removed. Equality is measured by the class-defined equality operator for type TTTT. T* rrrreeeemmmmoooovvvveeeeAAAAtttt(size_t i); Removes the object at index iiii and returns a pointer to it. An exception of type RRRRWWWWBBBBoooouuuunnnnddddssssEEEErrrrrrrroooorrrr will be thrown if iiii is not a valid index. Valid indices are from zero to the number of items in the list less one. T* rrrreeeemmmmoooovvvveeeeFFFFiiiirrrrsssstttt(); Removes the first item in the collection and returns a pointer to it. An exception of type RRRRWWWWBBBBoooouuuunnnnddddssssEEEErrrrrrrroooorrrr will be thrown if the list is empty. T* rrrreeeemmmmoooovvvveeeeLLLLaaaasssstttt(); Removes the last item in the collection and returns a pointer to it. An exception of type RRRRWWWWBBBBoooouuuunnnnddddssssEEEErrrrrrrroooorrrr will be thrown if the list is empty. void rrrreeeessssiiiizzzzeeee(size_t N); Changes the capacity of the collection to NNNN. Note that the number of objects in the collection does not change, just the capacity. RRRReeeellllaaaatttteeeedddd GGGGlllloooobbbbaaaallll OOOOppppeeeerrrraaaattttoooorrrrssss RWvostream& ooooppppeeeerrrraaaattttoooorrrr<<<<<<<<(RWvostream& strm, const RWTPtrOrderedVector<T>& coll); RWFile& ooooppppeeeerrrraaaattttoooorrrr<<<<<<<<(RWFile& strm, const RWTPtrOrderedVector<T>& coll); Saves the collection ccccoooollllllll onto the output stream ssssttttrrrrmmmm, or a reference to it if it has already been saved. RWvistream& ooooppppeeeerrrraaaattttoooorrrr>>>>>>>>(RWvistream& strm, RWTPtrOrderedVector<T>& coll); RWFile& ooooppppeeeerrrraaaattttoooorrrr>>>>>>>>(RWFile& strm, RWTPtrOrderedVector<T>& coll); Restores the contents of the collection ccccoooollllllll from the input stream ssssttttrrrrmmmm. PPPPaaaaggggeeee 6666 RRRRWWWWTTTTPPPPttttrrrrOOOOrrrrddddeeeerrrreeeeddddVVVVeeeeccccttttoooorrrr((((3333CCCC++++++++)))) RRRRWWWWTTTTPPPPttttrrrrOOOOrrrrddddeeeerrrreeeeddddVVVVeeeeccccttttoooorrrr((((3333CCCC++++++++)))) RWvistream& ooooppppeeeerrrraaaattttoooorrrr>>>>>>>>(RWvistream& strm, RWTPtrOrderedVector<T>*& p); RWFile& ooooppppeeeerrrraaaattttoooorrrr>>>>>>>>(RWFile& strm, RWTPtrOrderedVector<T>*& p); Looks at the next object on the input stream ssssttttrrrrmmmm and either creates a new collection off the heap and sets pppp to point to it, or sets pppp to point to a previously read instance. If a collection is created off the heap, then you are responsible for deleting it. PPPPaaaaggggeeee 7777